<?php
/*
 *   This file is part of Verbum.
 *
 *   poat is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   poat is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with poat.  If not, see <http://www.gnu.org/licenses/>.
 * 
 *   Copyright (c) 2008 Sergio Gabriel Teves <gabriel.sgt at gmail.com>
 */ 

class upload_data extends entity {

	var $id;
	var $objid;
	var $name;
	var $fileid;
	var $path;
	var $statusid;
	var $msg;
	var $pjid;
	var $filestatus;
	
    public function __construct()
    {
    }

	// THIS CREATE A NEW INSTANCE OF THIS CLASS
	public function newInstance() {
		return new upload_data;
	}

	// COMMON PUBLIC FUNCTIONS // NEEDED FOR LOADER
	public function get() {
		$sql = "SELECT * FROM ".UPLOADDATA." WHERE objid = ".util::str($this->objid)." AND fileid = ".util::str($this->fileid);
		return $sql;
	}

	public function listAll() {
		$sql = "SELECT * FROM ".UPLOADDATA." WHERE objid = ".util::str($this->objid);
		return $sql;
	}

	public function listOK() {
		$sql = "SELECT * FROM ".UPLOADDATA." WHERE objid = ".util::str($this->objid)." AND statusid = ".util::str(FILE_UPLOAD_OK);
		return $sql;
	}

	public function insert() {
		$sql = "INSERT INTO ".UPLOADDATA." (objid, name, fileid, path, statusid, msg,pjid, filestatus) ";
		$sql .= "VALUES (";
		$sql .=	util::str($this->objid);
		$sql .=	",".util::str($this->name);
		$sql .=	",".util::str($this->fileid);
		$sql .=	",".util::str($this->path);
		$sql .=	",".util::str($this->statusid);
		$sql .=	",".util::str($this->msg);	
		$sql .=	",".util::str($this->pjid);
		$sql .=	",".util::str($this->filestatus);		
		$sql .= ")";
		return $sql;
	}

	public function deleteFailed() {
		$sql = "DELETE FROM ".UPLOADDATA. " WHERE objid = ".util::str($this->objid)." AND statusid = ".util::str(FILE_UPLOAD_FAIL);
		return $sql;
	}
	
	public function deleteBy() {
		$sql = "DELETE FROM ".UPLOADDATA." WHERE ";
		$where = "";
		if ($this->objid!="") {
			$where .= " objid = ".util::str($this->objid);
		}
		if ($this->id!="") {
			if ($where!="") $where .= " AND ";
			$where .= " fileid = ".util::str($this->id);
		}
		if ($this->statusid!="") {
			if ($where!="") $where .= " AND ";
			$where .= " statusid = ".util::str($this->statusid);
		}		
	}
	public function delete() {
		$sql = "DELETE FROM ".UPLOADDATA. " WHERE objid = ".util::str($this->objid);
		return $sql;
	}

	public function fill($array) {
		$this->id=$array['id'];
		$this->objid=$array['objid'];
		$this->name=$array['name'];
		$this->fileid=$array['fileid'];
		$this->path=$array['path'];
		$this->statusid=$array['statusid'];
		$this->msg=$array['msg'];
		$this->pjid=$array['pjid'];
		$this->filestatus=$array['filestatus'];
	}

}

?>
